package com.kdyzm.demo.springboot;

import com.kdyzm.demo.springboot.utils.JavassitUtil;
import javassist.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.resultset.ResultSetWrapper;
import org.apache.ibatis.mapping.ResultMap;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Optional;

/**
 * @author kdyzm
 * @date 2022/1/20
 */
@SpringBootApplication
@Slf4j
public class Application {

    public static void main(String[] args) throws UnknownHostException {
        JavassitUtil.init();
        ConfigurableApplicationContext application = SpringApplication.run(Application.class, args);

        Environment env = application.getEnvironment();
        String[] activeProfiles = env.getActiveProfiles();
        Optional.ofNullable(activeProfiles.length).orElseGet(() -> 0);
        log.info("Application Startup Successful.配置参数个数："
            + Optional.ofNullable(activeProfiles.length).orElseGet(() -> 0));
        String host = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        log.info("\n----------------------------------------------------------\n\t" +
                "Application '{}' is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:{}\n\t" +
                "External: \thttp://{}:{}\n\t" +
                "----------------------------------------------------------",
            env.getProperty("spring.application.name"),
            env.getProperty("server.port"),
            host, port);
    }
}
